{% extends "base.html" %}

{% block head_title %}James Tauber{% if page.page_title %} : {{ page.page_title }}{% endif %}{% endblock %}

{% block extra_head %}
    <link rel="alternate" type="application/atom+xml" href="http://jtauber.com/atom/full/" />
    {% ifequal page.path '__home__' %}
        <link rel="openid.server" href="http://www.myopenid.com/server" />
        <link rel="openid.delegate" href="http://jtauber.myopenid.com/" />
        <meta name="verify-v1" content="LKFhycZ7OaS6mEMfTzlBsoSUCQasHEWqF/VeW6/FZTY=" />
    {% endifequal %}
{% endblock %}

{% block extra_commands %}
    <a href="/admin/cms/page/{{ page.id }}/">edit</a>
{% endblock %}

{% block right_content %}
    <div id="twitter_div">
        <h2 class="twitter-title">Twitter Updates</h2>
        <ul id="twitter_update_list"></ul>
    </div>
{% endblock %}

{% block main_content %}
    <p>{% for step in breadcrumbs %}<a href="/{{ step.1 }}/">{{ step.0 }}</a> &gt; {% endfor %}</p>
    
    {% if page.page_title %}<h2>{{ page.page_title }}</h2>{% endif %}
    
    {% ifequal page.path '__home__' %}
    <img id="portrait" src="/static/jtauber.jpg" alt="B/W picture of me" />
    {% endifequal %}
    {{ content|safe }}
    
    {% if category %}
        <div class="category_pages">
            <h3>Pages in this category</h3>
            <ul>
                {% for p in category_pages %}
                    <li>
                        <a href="/{{ p.path }}/">{{ p.page_title }}</a>
                        <span class="lastmod">({{ p.last_modified|date }}{% ifnotequal p.allow_comments "NO" %}{% if p.comment_set.count %} : {{ p.comment_set.count }} comment{{ p.comment_set.count|pluralize }}{% endif %}{% endifnotequal %})</span>
                    </li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
    
    {% if page.categories.count %}
        <div class="categories">
            <b>Categories:</b>
            {% for c in categories %}<br />
                {% if c.prev_page %}<a class="category_nav" href="/{{ c.prev_page.path }}/" title="{{ c.prev_page.page_title }}">prev</a> &laquo; {% endif %}
                <a href="/{{ c.category.term }}/">{{ c.category.term }}</a> 
                {% if c.next_page %} &raquo; <a class="category_nav" href="/{{ c.next_page.path }}/" title="{{ c.next_page.page_title }}">next</a> {% endif %}
            {% endfor %}
        </div>
    {% endif %}
    
    {% ifnotequal page.allow_comments "NO" %}
        <h4>Comments ({{ page.comment_set.count }})</h4>
        
        {% for comment in page.comments %}
            {% if comment.author %}
                <div class="comment_authenticated">
                    <p class="comment_citation">
                        <b>{{ comment.author.get_full_name }}</b>
                        on {{ comment.creation_time|date }}:
                    </p>
                    <div class="comment_content">{{ comment.formatted_comment|safe }}</div>
                </div>
            {% else %}
                <div class="comment">
                    <p class="comment_citation">
                        {% if comment.author_link %}
                            <a rel="nofollow" href="{{ comment.author_link }}"><b>{% if comment.author_name %}{{ comment.author_name }}</b>{% else %}anonymous{% endif %}</a> 
                        {% else %}
                            {% if comment.author_name %}<b>{{ comment.author_name }}</b>{% else %}anonymous{% endif %}
                        {% endif %}
                        {% if user.is_authenticated %}
                            {% if comment.author_email %}
                                <a href="mailto:{{ comment.author_email }}">{{ comment.author_email }}</a>
                            {% endif %}
                            {% if comment.author_ipaddress %}
                                <tt>({{ comment.author_ipaddress.strip }})</tt>
                            {% endif %}
                        {% endif %}
                        on {{ comment.creation_time|date }}:
                    </p>
                    <div class="comment_content">{{ comment.formatted_comment|safe }}</div>
                </div>
            {% endif %}
        {% endfor %}
    {% endifnotequal %}
    
    {% ifequal page.allow_comments "YES" %}
        <h4><a href="#" id="add_comment_toggle">Add a Comment</a></h4>
        <form class="add_comment" action="" method="post" style="display: none;">
            {% if comment_error %}
                <p class="comment_error">{{ comment_error}}</p>
            {% endif %}
            
            <table>
                {% if user.is_authenticated %}
                <tr><td colspan="2">as you are authenticated as <b>{{ user }}</b>, you don't need to provide your details.</td></tr>
                {% else %}
                <tr> 
                    <th> What is {{ math_i }} + {{ math_j }}? </th>
                    <td><input type="text" name="math_answer" size="3"/>
                        <input type="hidden" name="math_verification" value="{{ math_key }}"/>
                    </td>
                </tr>
                <tr>
                    <th>Name</th>
                    <td><input type="text" name="author_name" value="{{ author_name }}" size="30"/></td>
                </tr>
                <tr>
                    <th>Link (optional)</th>
                    <td><input type="text" name="author_link" value="{{ author_link }}" size="30"/></td>
                </tr>
                <tr>
                    <th>Email (not shown)</th>
                    <td><input type="text" name="author_email" value="{{ author_email }}" size="30"/></td>
                </tr>
                {% endif %}
                <tr>
                    <th>Comment</th>
                    <td>
                        <textarea name="comment_content" rows="10" cols="40">{{ comment_content }}</textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="Submit comment"/>
                    </td>  
                </tr>      
                <tr><td colspan="2">Comments are text only.</td></tr> 
                <tr><td colspan="2">Email address will not be shown publicly but you may use it if you want the author to contact you.</td></tr> 
                <tr><td colspan="2">The math question is to ensure you are a human!</td></tr>
            </table>
        </form>
    {% endifequal %}
    
{% endblock %}

{% block bottom_content %}
  Created: {{ page.creation_time|date }}<br />
  Last Modified: {{ page.last_modified|date }}<br />
  Author: {{ page.author }}
{% endblock %}

{% block extra_scripts %}      
    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
    <script type="text/javascript">
        _uacct = "UA-175899-1";
        urchinTracker();
    </script>
    <script type="text/javascript" src="/static/jquery.js"></script>
    <script type="text/javascript">
        function scrollTo(selector) {
            var targetOffset = $(selector).offset().top;
            $('html,body').animate({scrollTop: targetOffset}, 500);
        }
        $(document).ready(function() {
            $('#add_comment_toggle').click(function() {
                $('form.add_comment').slideToggle();
                scrollTo('form.add_comment');
                return false;
            });
            {% if comment_error %}
            $('form.add_comment').show();
            scrollTo('.comment_error');
            {% endif %}
        });
    </script>
{% endblock %}
